package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOperation{
    @Override
    public void work(BookList booklist) {
        System.out.println("借阅图书：");
        System.out.println("请输入你要借阅的书的书名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        System.out.println("请输入图书的作者：");
        String author = scanner.nextLine();
        int currentSize = booklist.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = booklist.getBook(i);
            if((book.getName().equals(name)&&book.getAuthor().equals(author))&& ! book.isBorrowed()){
                book.setBorrowed(true);
                System.out.println("借阅成功！");
                return;
            }
        }
        System.out.println("借阅失败！该书不存在或者已被借出！");
    }
}
